package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
//import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class FourthActivity extends BaseActivity implements View.OnClickListener {
    private int score3 = 0;
    private CheckBox t3_1;
    private CheckBox t3_2;
    private CheckBox t3_3;
    private CheckBox t3_4;
    private Button prev2;
    private Button next2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fourth_layout);
        initView();
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        score3 = bundle.getInt("score2");

//        Toast.makeText(FourthActivity.this, "第一题和第二题的所得分数为" + score3, Toast.LENGTH_SHORT).show();
    }

    private void initView() {
        t3_1 = (CheckBox) findViewById(R.id.t3_1);
        t3_2 = (CheckBox) findViewById(R.id.t3_2);
        t3_3 = (CheckBox) findViewById(R.id.t3_3);
        t3_4 = (CheckBox) findViewById(R.id.t3_4);
        prev2 = (Button) findViewById(R.id.prev2);
        next2 = (Button) findViewById(R.id.next2);

        t3_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (t3_2.isChecked()){
                    score3 += 20;
                }
            }

        });

        t3_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (t3_3.isChecked()){
                    score3 += 20;
                }
            }

        });

        t3_4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (t3_4.isChecked()){
                    score3 += 20;
                }
            }

        });

        prev2.setOnClickListener(this);
        next2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.prev2:
                Intent intent = new Intent(FourthActivity.this,ThirdActivity.class);
                startActivity(intent);
                break;
            case R.id.next2:
//                Toast.makeText(FourthActivity.this, "前三题的所得分数为" + score3, Toast.LENGTH_SHORT).show();
                //创建意图对象
                Intent intent2 = new Intent(FourthActivity.this, FifthActivity.class);
//        传递数据
                Bundle bundle = new Bundle();
                bundle.putInt("score3", score3);
                intent2.putExtras(bundle);
                //激活意图
                startActivity(intent2);
                break;
        }
    }
}